package com.sgb.jicai.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.DetailsBean;
import com.sgb.jicai.entity.PriceRulesBean;
import com.sgb.jicai.weight.ProcurementCountPrice;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * Time:2021/7/28
 * AUTHOR:F_Q
 * Description:规格和价格的adapter
 */
public class SpecsPriceAdaptrer extends BaseRecycleAdapter<DetailsBean> {

    private boolean isProductModels;
    public SpecsPriceAdaptrer(Context context, List<DetailsBean> datas,boolean isProductModel) {
        super(context, R.layout.item_specs_price, datas);
        isProductModels = isProductModel;
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        holder.itemView.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                operationdelete.Delete(position);
            }
        });
        ProcurementCountPrice ProcurementCountPrice = holder.itemView.findViewById(R.id.procurement_count_price);
        ProcurementCountPrice.setUnit(datas.get(position).getUnitName());
        ItemInputTextView original_price = holder.itemView.findViewById(R.id.original_price);//原价 纯数字
        original_price.setInfilterType(ItemInputTextView.TYPE_NUM);//纯数字
        if (isProductModels){
            if (datas.get(position)!=null&&datas.get(position).getPriceRules()!=null&&datas.get(position).getPriceRules().size()>0){
                ProcurementCountPrice.setData(datas.get(position).getPriceRules());
            }
        }
        List<PriceRulesBean> data = ProcurementCountPrice.getData();
        datas.get(position).setPriceRules(data);
    }

    @Override
    public void convert(ItemViewHolder holder, DetailsBean entity) {
        holder.setBinding(BR.viewModel, entity);
    }

    private OperationDelete operationdelete;

    public void setOperationDelete(SpecsPriceAdaptrer.OperationDelete operationDelete) {
        operationdelete = operationDelete;
    }

    public interface OperationDelete{
        void Delete(int pos);
    }
}
